<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .box {
      width: 200px;
      height: 200px;
      background-color: #6ff;
      margin: 50px;
      overflow: hidden;
    }

    .sub {
      width: 100px;
      height: 100px;
      background-color: #00f;
      margin: 50px;
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="sub"></div>
  </div>
</body>
<script>
  var box = document.getElementsByClassName("box")[0];



  // 问题: 给父元素绑定onmouseover,onmouseout 从父元素滑到子元素时会先触发划出 在触发划入

  // 解决方法:
  // onmouseenter => 替换 onmouseover
  // onmouseleave => 替换 onmouseout

  /*   // onmouseover   鼠标划入触发 
    box.onmouseover = function(){
        console.log("鼠标划入");
        this.style.background = "red";
    }
    // onmouseout   鼠标划入触发
    box.onmouseout = function(){
        console.log("鼠标划出");
        this.style.background = "#6ff";
    } */


  // onmouseover   鼠标划入触发 
  box.onmouseenter = function () {
    console.log("鼠标划入");
    this.style.background = "red";
  }
  // onmouseout   鼠标划入触发
  box.onmouseleave = function () {
    console.log("鼠标划出");
    this.style.background = "#6ff";
  }




</script>

</html>